﻿//-- =============================================
//-- Author:	    Amir Javan
//-- Create date:   1390/2/6
//-- Description:	PayAndReceive Factory Class 
//-- E-Mail:    	amsjavan@yahoo.com
//-- Mobile:        09355276131
//-- Last Update:   1390/02/06 19:36
//-- =============================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ChequeManagement.BLL
{
    /// <summary>
    ///  This Class contains number of constructor, method that Inheritance of "BaseFactory" Class
    /// </summary>
    /// <constructor>this constructor called base constructor and set parameter</constructor>
    /// <method>this class includes some method for add,edit,getall,remove data</method>
    public class BLLPayAndReceiveFactory : BaseFactory
    {
        private ChequeManagement.DAL.DALPayAndReceive dataObject = null;

        /// <summary>
        /// This constructor called base constructor and set parameter that parameter value is "BLLPayAndReceive"
        /// and use on create instance of class
        /// </summary>
        /// <base constructor>base constructor name is "BaseFactory" that get tableName and set tableName with this tableName</base constructor> 
        public BLLPayAndReceiveFactory()
            : base("PayAndReceive")
        {
            dataObject = (ChequeManagement.DAL.DALPayAndReceive)(base.DataAccessLayer);
        }

        /// <summary>
        /// This method get a object that type is BLLPayAndReceive and check this object is valid or not valid if object is not valid throw a exception
        /// else if object is valid create a instance of ChequeManagement.DAL.DALPayAndReceive class and call Insert method and set parameter
        /// </summary>
        /// <param name="payAndRecieveObj" Type="BLLPayAndReceive"></param>
        /// <return>this type is void and Do not return</return>
        public void Add(BLLPayAndReceive payAndRecieveObj)
        {
            try
            {
                if (payAndRecieveObj.IsValid() == false)
                    throw (new ChequeManagement.Validation.InvalidBusinessObjectException(payAndRecieveObj.Errors));
                dataObject.Insert(payAndRecieveObj);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method get a object that type is BLLPayAndReceive and a object that type is int
        /// if payAndReceiveObj parameter is IsValid this method call dataObject that type is ChequeManagement.DAL.DALPayAndReceive and call Update method and set parameter
        /// else if payAndReceiveObj parameter not is IsValid throw exception
        /// </summary>
        /// <param name="payAndReceiveObj" Type="BLLPayAndReceive"></param>
        /// <param name="targetPayAndReceiveID" Type="int"></param>
        /// <return>this type is void and Do not return</return>
        public void Edit(BLLPayAndReceive payAndReceiveObj, int targetPayAndReceiveID)
        {
            try
            {

                if (payAndReceiveObj.IsValid() == false)
                    throw (new ChequeManagement.Validation.InvalidBusinessObjectException(payAndReceiveObj.Errors));

                dataObject.Update(payAndReceiveObj, targetPayAndReceiveID);
            }

            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have a parameter that type is DataTable
        /// and call dataObject that type is ChequeManagement.DAL.DALPayAndReceive and call FetchAll method and set parameter for select all data
        /// </summary>
        /// <param name="dataTable" Type="DataTable"></param>
        /// <return>this type is void and Do not return but parameter is DataTable and result return into this DataTable</return>
        public void GetAll(DataTable dataTable)
        {
            try
            {
                dataObject.FetchAll(dataTable);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        ///  This method not have parameter
        /// and call dataObject that type is ChequeManagement.DAL.DALPayAndReceive and call FetchAll method for select all data
        /// </summary>
        ///  <returns>this method select all data and result return into List<> that type is BLLPayAndReceive</returns>
        public List<BLLPayAndReceive> GetAll()
        {
            try
            {
                return (dataObject.FetchAll());
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameters
        /// and call dataObject that type is ChequeManagement.DAL.DALPayAndReceive and call FetchByField method and set parameters
        /// the filedname parameter select field name on select table and vlaue parameter select value that select field name and result return into dataTable parameter 
        /// </summary>
        /// <param name="fieldName" Type="BLLPayAndReceive.PayAndReceiveField"></param>
        /// <param name="value" Type="object"></param>
        /// <param name="dataTable" Type="DataTable"></param>
        /// <return>this type is void and Do not return but parameter is DataTable and result return into this DataTable</return>
        public void GetByField(BLLPayAndReceive.PayAndReceiveField fieldName, object value, DataTable dataTable)
        {
            try
            {
                dataObject.FetchByField(fieldName.ToString(), value, dataTable);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameter
        /// and call dataObject that type is ChequeManagement.DAL.DALPayAndReceive and call FetchByField method and set parameters
        /// the filedname parameter select field name on select table and vlaue parameter select value that select field name
        /// </summary>
        /// <param name="fieldName" Type="BLLPayAndReceive.PayAndReceiveField"></param>
        /// <param name="value" Type="object"></param>
        /// <returns>this method select data and result return into List<> that type is BLLPayAndReceive</returns>
        public List<BLLPayAndReceive> GetByField(BLLPayAndReceive.PayAndReceiveField fieldName, object value)
        {
            try
            {
                return (dataObject.FetchByField(fieldName.ToString(), value));
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameter
        /// and call dataObject that type is ChequeManagement.DAL.DALPayAndReceive and call FetchAllByCondition method and set parameters
        /// select data by this condition 
        /// </summary>
        /// <param name="condition" Type="string"></param>
        /// <param name="dataTable" Type="ref DataTable"></param>
        /// <return>this type is void and Do not return but parameter is DataTable and result return into this DataTable</return>
        public void GetAllByCondition(string condition, DataTable dataTable)
        {
            try
            {
                dataObject.FetchAllByCondition(condition, dataTable);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameter
        /// and call dataObject that type is ChequeManagement.DAL.DALPayAndReceive and call FetchByKey method and set parameters
        /// select data by targetPayAndReceiveID
        /// </summary>
        /// <param name="targetPayAndReceiveID" Type="int"></param>
        /// <returns>object that type is BLLPayAndReceive</returns>
        public BLLPayAndReceive GetByKey(int targetPayAndReceiveID)
        {
            try
            {
                return (dataObject.FetchByKey(targetPayAndReceiveID));
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameter
        /// and call dataObject that type is ChequeManagement.DAL.DALPayAndReceive and call Delete method and set parameters
        /// </summary>
        /// <param name="targetPayAndReceiveID" Type="int"></param>
        /// <return>this type is void and Do not return</return>
        public void Remove(int targetPayAndReceiveID)
        {
            try
            {
                dataObject.Delete(targetPayAndReceiveID);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameter
        /// and call dataObject that type is ChequeManagement.DAL.DALPayAndReceive and call Delete method and set parameters
        /// remove field from table by this fieldName that value is this value
        /// </summary>
        /// <param name="fieldName" Type="BLLPayAndReceive.PayAndReceiveField"></param>
        /// <param name="value" Type="object"></param>
        /// <return>this type is void and Do not return</return>
        public void Remove(BLLPayAndReceive.PayAndReceiveField fieldName, object value)
        {
            try
            {
                dataObject.Delete(fieldName.ToString(), value);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
    }
}

